<?php
class My_Plugins_Env extends Zend_Controller_Plugin_Abstract
{
	public function dispatchLoopStartup(Zend_Controller_Request_Abstract $req)
	{
		// Start Zend_Session
		Zend_Session::start();
		
		// Setup layout
		$module = strtolower($req->getParam('module'));
		$controller = strtolower($req->getParam('controller'));
		$action = strtolower($req->getParam('action'));
		
		if($module == 'admin') {
			//Layout setup
        	$layout_instance = Zend_Layout::startMvc(
                array(
                'layout'     => 'layout',
                'layoutPath' => APPLICATION_PATH.'/layout/'.$module,
                'contentKey' => 'content'
                )
       		);
       		
       		// Check Login Admin Zone
       		if(!($controller == 'user' && $action == 'login')) {
				$isLogin = new Zend_Session_Namespace('admin');
				if(!isset($isLogin->login)) {
					// Forward to login action
					$config = My_Globals::getConfiguration();
					$this->getResponse()->setRedirect($config->site->live.'/admin/user/login/');
				}
       		}
		}
	}
}